package com.zxjbyte.yiyi.extension.job.core.alarm;

import cn.hutool.core.util.StrUtil;
import com.zxjbyte.yiyi.extension.job.enums.JobAlarmTypeEnum;
import lombok.Data;

/**
 * 告警参数：任务执行过程中传递的数据
 *
 * @Author zhangxingjia
 * @Date 2024/6/19 16:24
 * @Version: 1.0
 */
@Data
public class AlarmPayload {

    // 任务唯一id
    private Long jobId;

    // cron表达式
    private String cronExpression;

    // 触发报警类型
    private JobAlarmTypeEnum alarmType;

    // 任务执行超时时间
    private Long timeout;

    // 报警邮件负责人
    private String author;

    // 报警邮件地址, 多个,分隔
    private String[] emailAddress;

    public static AlarmPayload of(Long jobId, String cronExpression, String alarmType, Long timeout, String author, String emailAddress){
        AlarmPayload alarmPayload = new AlarmPayload();
        alarmPayload.setJobId(jobId);
        alarmPayload.setCronExpression(cronExpression);
        alarmPayload.setAlarmType(JobAlarmTypeEnum.get(alarmType));
        alarmPayload.setTimeout(timeout);
        alarmPayload.setAuthor(author);
        alarmPayload.setEmailAddress(StrUtil.splitToArray(emailAddress, ","));
        return alarmPayload;
    }
}
